define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'zhanting/index' + location.search,
                    add_url: 'zhanting/add',
                    edit_url: 'zhanting/edit',
                    del_url: 'zhanting/del',
                    multi_url: 'zhanting/multi',
                    import_url: 'zhanting/import',
                    table: 'zhanting',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,         //搜索框
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), operate: false },
                        { field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'province_city_text', title: __('Province_city'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'urban_city_text', title: __('Urban_city'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'district_city_text', title: __('District_city'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        {
                            field: 'province_city',
                            title: __('Province_city'),
                            searchList: $.getJSON('ajax/getProvince'),
                            formatter: Table.api.formatter.content,
                            visible: false,
                        },
                        // {
                        //     field: 'urban_city',
                        //     title: __('urban_city'),
                        //     searchList: $.getJSON('ajax/getCity', { pid: $('select[name="province_city"]').val() }),
                        //     formatter: Table.api.formatter.content
                        // },
                        // {
                        //     field: 'district_city',
                        //     title: __('district_city'),
                        //     searchList: $.getJSON('ajax/getProvince'),
                        //     formatter: Table.api.formatter.content
                        // },
                        // { field: 'urban_city', title: __('Urban_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        // { field: 'district_city', title: __('District_city'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'address', title: __('Address'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'tel', title: __('Tel'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'wechat_image', title: __('Wechat_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'businesshours', title: __('Businesshours'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content },
                        { field: 'video_file', title: __('Video_file'), operate: false, formatter: Table.api.formatter.file },
                        // {field: 'content', title: __('Content')},
                        { field: 'status', title: __('Status'), searchList: { "1": __('Status 1'), "2": __('Status 2') }, formatter: Table.api.formatter.status },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime },
                        { field: 'weigh', title: __('Weigh'), operate: false },
                        { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
